package com.neusoft.restaurant.controller;


import com.neusoft.restaurant.config.utils.R;
import com.neusoft.restaurant.entity.PageResult;
import com.neusoft.restaurant.entity.ResCollect;
import com.neusoft.restaurant.service.IResCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 收藏Controller
 * 
 * @author zhongda
 * @date 2023-12-09
 */
@RestController
@RequestMapping("/api/collect")
public class ResCollectController extends BaseController
{
    @Autowired
    private IResCollectService resCollectService;

    /**
     * 查询收藏列表
     */

    @GetMapping("/list")
    public R list(ResCollect resCollect)
    {
//        startPage();
        List<ResCollect> list = resCollectService.selectResCollectList(resCollect);
        return R.success(list);
    }

    /**
     * 分页查询收藏列表
     */
    @GetMapping("/list2")
    public R list2(ResCollect resCollect,Integer pageNum,Integer pageSize)
    {
        PageResult list = resCollectService.selectResCollectList2(resCollect,pageNum,pageSize);
        return R.success(list);
    }


    /**
     * 获取收藏详细信息
     */
    @GetMapping(value = "/{id}")
    public R getInfo(@PathVariable("id") Long id)
    {
        return R.success(resCollectService.selectResCollectById(id));
    }

    /**
     * 新增收藏
     */
    @PostMapping
    public R add(@RequestBody ResCollect resCollect)
    {
        return R.toAjax(resCollectService.insertResCollect(resCollect));
    }

    /**
     * 修改收藏
     */
    @PutMapping
    public R edit(@RequestBody ResCollect resCollect)
    {
        return R.toAjax(resCollectService.updateResCollect(resCollect));
    }

    /**
     * 删除收藏
     */
	@DeleteMapping("/{ids}")
    public R remove(@PathVariable Long[] ids)
    {
        return R.toAjax(resCollectService.deleteResCollectByIds(ids));
    }
}
